package com.ccys.cms.controller.userManagement;

import com.ccys.cms.service.userManagement.DoctorService;
import com.ccys.common.constants.ContextConstants;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.userManagement.DoctorAppointmentSettingDto;
import com.ccys.db.dto.userManagement.DoctorDto;
import com.ccys.db.entity.TblDoctorConsultFee;
import com.ccys.db.vo.userManagement.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.text.ParseException;
import java.util.List;

/**
 * @program: WhiteCoat
 * @description: 医生接口
 * @author: ZhangJingCan
 * @create: 2023-12-18 16:34
 **/

@RestController
@RequestMapping("userManagement")
@Api(tags = "userManagement-医生接口")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;


    @PostMapping("doctor")
    @ApiOperation("保存医生")
    public ResponseResult saveDoctor(@RequestBody DoctorDto dto) throws ParseException {
        return doctorService.saveDoctor(dto);
    }

    @PutMapping("doctor")
    @ApiOperation("修改医生")
    public ResponseResult edit(@RequestBody DoctorDto dto) throws ParseException {
        return doctorService.saveDoctor(dto);
    }

    @DeleteMapping("doctor")
    @ApiOperation("根据ID删除医生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult deleteDoctor(@ApiIgnore DoctorDto dto) {
        return doctorService.deleteDoctor(dto);
    }


    @GetMapping("doctor")
    @ApiOperation("分页查询医生(医生诊断数据统计的分页也在这里)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "name", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "DoctorNo", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "email", value = "email", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "companyId", value = "companyId/查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "panelType", value = "医生类型:1SP ; 2:GP/查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "0/1,查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "orderByStr",
                    value = "(默认传：t1.created_on descend),(左到右依次:t1.first_name,t3.company_name,t1.disp_order,t1.login_status,t1.status,t2.user_fullname,t1.created_on)",
                    required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<PageInfo<DoctorPageQueryVo>, Object> findPageDoctor(@ApiIgnore DoctorDto dto) {
        return doctorService.findPageDoctor(dto);
    }

    @GetMapping("doctor/details")
    @ApiOperation("根据医生ID查询详情(编辑和INFO都可以用)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id(医生ID)", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<DoctorDetailsVo, Object> findDoctorDetailsByDoctorId(@ApiIgnore DoctorDto dto) {
        return doctorService.findDoctorDetailsByDoctorId(dto);
    }

    @GetMapping("doctor/info/favouritePrescription")
    @ApiOperation("医生Info里面的处方分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id(医生ID)", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<PageInfo<DoctorInfoFavouritePrescriptionPageVo>, Object> findDoctorInfoFavouritePrescription(@ApiIgnore DoctorDto dto) {
        return doctorService.findDoctorInfoFavouritePrescription(dto);
    }


    @GetMapping("doctor/info/flagPatient")
    @ApiOperation("查询医生Info里面的患者标签列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id(医生ID)", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "memberName", value = "memberName(模糊搜索)", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "flagName", value = "flagName(模糊搜索)", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始日期,格式:yyyy-MM-dd", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期,格式:yyyy-MM-dd", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "orderByStr",
                    value = "(默认传：t1.created_on descend),(左到右依次:memberName,t3.name,t1.created_on)",
                    required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<List<DoctorInfoFlagPatientVo>, Object> findDoctorInfoFlagPatient(@ApiIgnore DoctorDto dto) {
        return doctorService.findDoctorInfoFlagPatient(dto);
    }


    @PutMapping("doctor/status")
    @ApiOperation("根据ID修改医生状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态：0-禁用，1-启用", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateDoctorStatus(@ApiIgnore DoctorDto dto) {
        return doctorService.updateDoctorStatus(dto);
    }

    @PutMapping("doctor/loginStatus")
    @ApiOperation("根据ID修改医生登录状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "loginStatus", value = "默认-1允许登录，0-不允许登录", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateDoctorLoginStatus(@ApiIgnore DoctorDto dto) {
        return doctorService.updateDoctorLoginStatus(dto);
    }

    @PutMapping("doctor/dispOrder")
    @ApiOperation("根据ID修改医生排序")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "dispOrder", value = "序号", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateDoctorDispOrder(@ApiIgnore DoctorDto dto) {
        return doctorService.updateDoctorDispOrder(dto);
    }

    @PostMapping("doctor/doctorRosterSetting")
    @ApiOperation("保存医生的排班设置(Roster Setting)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "当前医生ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "minBlockBookable", value = "最小可预约时间数，如设置 1 小时，则可预约 1 小时以后的医生时间", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "minBlockBookableUnit", value = "时间单位:1minute 2hour 3day 4month", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "maxBlockBookable", value = "最大可预约时间数，如设置 1 小时，则可预约 1 小时以内的医生时间", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "maxBlockBookableUnit", value = "时间单位:1minute 2hour 3day 4month", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "blockIntervalMinute", value = "间隔时长", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "bufferPeriodMinute", value = "每个预约时间点的缓冲时长", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "eapBlockIntervalMinute", value = "EAP间隔时长", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "eapBufferPeriodMinute", value = "EAP每个预约时间点的缓冲时长", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "workOnHoliday", value = "是否在公共假日工作,0-否，1-是", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult saveDoctorRosterSetting(@ApiIgnore DoctorDto dto) {
        return doctorService.saveDoctorRosterSetting(dto);
    }

    @PostMapping("doctor/doctorSchedule")
    @ApiOperation("保存医生的排班(排班表数据)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "当前排班表ID/修改需要传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "doctorId", value = "医生ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "clinicId", value = "诊所ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "shiftType", value = "类型：1 work 2 leave", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间,格式：yyyy-MM-dd HH:mm", required = true, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间,格式：yyyy-MM-dd HH:mm", required = true, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "leaveAllDay", value = "shiftType为2-leave的时候，这个字段必传，0-否，1-是", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "repeatType", value = "shiftType类型为：work必传,重复类型：0-不重复,1-每日,2-每周,3-每月", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "repeatEndTime", value = "repeatType类型不为0的时候必传,重复结束时间", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "forOnlineConsult", value = "shiftType为1-work必传，是否在线咨询：0-否，1-是", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "forWalkinConsult", value = "shiftType为1-work必传，是否门诊咨询：0-否，1-是", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "forOnlineAppointment", value = "shiftType为1-work必传，是否网上预约：0-否，1-是", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "forWalkinAppointment", value = "shiftType为1-work必传，是否门诊预约：0-否，1-是", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "forEapAppointment", value = "shiftType为1-work必传，是否EAP-网上预约：0-否，1-是", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "forEapWalkinAppointment", value = "shiftType为1-work必传，是否EAP-门诊预约：0-否，1-是", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "forTextBasedAppointment", value = "shiftType为1-work必传，是否在线文字聊天：0-否，1-是", required = false, dataType = "string", paramType = "query"),
    })
    public ResponseResult saveDoctorSchedule(@ApiIgnore DoctorAppointmentSettingDto dto) {
        return doctorService.saveDoctorSchedule(dto);
    }

    @PutMapping("doctor/doctorSchedule")
    @ApiOperation("保存医生的排班(排班表数据)")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "当前排班表ID/修改需要传", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "doctorId", value = "医生ID", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "clinicId", value = "诊所ID", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "shiftType", value = "类型：1 work 2 leave", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "startTime", value = "开始时间,格式：yyyy-MM-dd HH:mm", required = true, dataType = "date", paramType = "query"),
        @ApiImplicitParam(name = "endTime", value = "结束时间,格式：yyyy-MM-dd HH:mm", required = true, dataType = "date", paramType = "query"),
        @ApiImplicitParam(name = "leaveAllDay", value = "shiftType为2-leave的时候，这个字段必传，0-否，1-是", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "repeatType", value = "shiftType类型为：work必传,重复类型：0-不重复,1-每日,2-每周,3-每月", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "repeatEndTime", value = "repeatType类型不为0的时候必传,重复结束时间", required = false, dataType = "date", paramType = "query"),
        @ApiImplicitParam(name = "forOnlineConsult", value = "shiftType为1-work必传，是否在线咨询：0-否，1-是", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "forWalkinConsult", value = "shiftType为1-work必传，是否门诊咨询：0-否，1-是", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "forOnlineAppointment", value = "shiftType为1-work必传，是否网上预约：0-否，1-是", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "forWalkinAppointment", value = "shiftType为1-work必传，是否门诊预约：0-否，1-是", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "forEapAppointment", value = "shiftType为1-work必传，是否EAP-网上预约：0-否，1-是", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "forEapWalkinAppointment", value = "shiftType为1-work必传，是否EAP-门诊预约：0-否，1-是", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "forTextBasedAppointment", value = "shiftType为1-work必传，是否在线文字聊天：0-否，1-是", required = false, dataType = "string", paramType = "query"),
    })
    public ResponseResult editDoctorSchedule(@ApiIgnore DoctorAppointmentSettingDto dto) {
        return doctorService.saveDoctorSchedule(dto);
    }

    @DeleteMapping("doctor/doctorSchedule")
    @ApiOperation("删除医生排班")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "deleteType", value = "删除类型:0-今天，1-今天和以后，2删除所有", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "deleteType为0传,选择的当天开始时间,格式：yyyy-MM-dd HH:mm", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "deleteType为0传,选择的当天结束时间,格式：yyyy-MM-dd HH:mm", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "repeatEndTime", value = "deleteType为1传，重复结束时间,选择的当天减去一天时间,格式：yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
    })
    public ResponseResult deleteDoctorSchedule(@ApiIgnore DoctorAppointmentSettingDto dto) {
        return doctorService.deleteDoctorSchedule(dto);
    }

    @GetMapping("doctor/doctorSchedule")
    @ApiOperation("查询医生排班")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "医生ID/查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "groupId", value = "groupId/查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "clinicId", value = "诊所ID/查询所有传null", required = false, dataType = "string", paramType = "query"),
    })
    public ResponseResult<List<DoctorAppointmentSettingFindListVo>, Object> findListDoctorSchedule(@ApiIgnore DoctorDto dto) {
        return doctorService.findListDoctorSchedule(dto);
    }

    @GetMapping("doctor/doctorConsultFee")
    @ApiOperation("查询医生费用-根据医生ID")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctorId", value = "医生ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<List<TblDoctorConsultFee>, Object> findListDoctorConsultFee(@ApiIgnore TblDoctorConsultFee dto) {
        return doctorService.findListDoctorConsultFee(dto);
    }

    /**
     * @description 获取可选择医生列表
     * @date 2023/12/27
     * @author cloud fly
     */
    @GetMapping("doctor/listSelect")
    @ApiOperation("获取可选择医生列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "firstName + lastName", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "email", value = "email", required = false, dataType = "string", paramType = "query"),

    })
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC, response = DoctorSelectWebVO.class)
    })
    public ResponseResult listSelect(@ApiIgnore DoctorDto dto) {
        return this.doctorService.listSelect(dto);
    }


    @GetMapping("doctor/doctorYearOfPractice")
    @ApiOperation("获取医生工作年份")
    public ResponseResult<List<DoctorYearOfPracticeListVo>, Object> doctorYearOfPractice() {
        return this.doctorService.doctorYearOfPractice();
    }

    @GetMapping("doctor/findListByCountryId")
    @ApiOperation("下拉列表，返回：(id、firstName、lastName、email)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "countryOfResidence", value = "医生所在国家", required = false, dataType = "string", paramType = "query"),
    })
    public ResponseResult<List<DoctorFindListSelectVo>, Object> findListByCountryId(@ApiIgnore DoctorDto dto) {
        return this.doctorService.findListByCountryId(dto);
    }

}
